package com.baizhi.service.impl;

import com.baizhi.entity.CmfzAdmin;
import com.baizhi.mapper.CmfzAdminMapper;
import com.baizhi.realm.MyPermissionRealm;
import com.baizhi.service.CmfzAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhengg
 * @since 2020-07-26
 */
@Service
public class CmfzAdminServiceImpl extends ServiceImpl<CmfzAdminMapper, CmfzAdmin> implements CmfzAdminService {
    private static final Logger logger = LoggerFactory.getLogger(CmfzAdminServiceImpl.class);
    @Override
    public boolean login(String name, String pwd) {
        Subject subject = SecurityUtils.getSubject();
        try {
            subject.login(new UsernamePasswordToken(name, pwd));
        } catch (UnknownAccountException e) {
            logger.info("账户异常");
            return false;
        }catch (IncorrectCredentialsException e){
            logger.info("密码异常");
            return false;
        }
        return true;
    }
    @RequiresPermissions("banner:add")
    @Override
    public void testHas() {
        logger.info("------进入testHas方法--------------");
    }
    @RequiresPermissions("banner:delete")
    @Override
    public void testNo() {
        logger.info("------进入testNo方法--------------");
    }
}
